package com.vooda.controller;

import com.vooda.dto.vo.BaseResult;
import com.vooda.dto.vo.HomeImagesVo;
import com.vooda.dto.vo.MarketVo;
import com.vooda.dto.vo.StoreVo;
import com.vooda.service.HomePageService;
import com.vooda.service.MarketService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Scope;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;

/**
 * @author KennyDavid
 */

@Slf4j
@Api(description = "主页")
@RestController
@RequestMapping("/home")
@Scope("prototype")
@Validated
public class HomeController {

    private HomePageService homePageService;
    private MarketService marketService;

    public HomeController(HomePageService homePageService, MarketService marketService) {
        this.homePageService = homePageService;
        this.marketService = marketService;
    }

    @ApiOperation(value = "主页轮播图")
    @GetMapping("/rotateImages")
    public BaseResult<List<HomeImagesVo>> getRotateImages() {
        return homePageService.getRotateImages();
    }

    @ApiOperation(value = "超市商户分页列表")
    @GetMapping("/marketList")
    public BaseResult<List<MarketVo>> getMarketList(@ApiParam("创建时间") @RequestParam(required = false) Date createTime,
                                                    @ApiParam("每页条数") @RequestParam(required = false, defaultValue = "10") Integer size) {
        return marketService.getMarketList(createTime, size);
    }

    @ApiOperation(value = "超市的更多商户")
    @GetMapping("/marketList/{marketId}")
    public BaseResult<List<StoreVo>> getMarketList(@ApiParam(value = "超市id", required = true) @PathVariable Long marketId,
                                                   @ApiParam("创建时间") @RequestParam(required = false) Date createTime,
                                                   @ApiParam("每页条数") @RequestParam(required = false, defaultValue = "10") Integer size) {
        return marketService.getMoreStore(marketId,createTime,size);
    }
}
